package com.dianxin.smartpark.web.device;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.chinatelecom.response.common.CommonResponseBody;
import com.dianxin.device.api.device.dto.SmartDeviceDTO;
import com.dianxin.device.api.device.dto.SmartDeviceSettingsDTO;
import com.dianxin.device.api.device.qo.SmartDeviceNoAclRpcQO;
import com.dianxin.device.api.device.qo.SmartDeviceRpcQO;
import com.dianxin.smartpark.service.device.SmartParkDeviceService;
import com.dianxin.smartpark.service.device.SmartParkDeviceSettingsService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 设备管理
 *
 * @author wangkai
 */
@RestController
@RequestMapping("/smartpark/device")
public class SmartParkDeviceController {

    @Resource
    private SmartParkDeviceService smartParkDeviceService;

    @Resource
    private SmartParkDeviceSettingsService smartParkDeviceSettingsService;

    /**
     * 查询设备列表
     *
     * @param qo qo
     * @return
     */
    @SaCheckPermission
    @RequestMapping("/getDevices")
    public CommonResponseBody<List<SmartDeviceDTO>> getDevices(@RequestBody SmartDeviceRpcQO qo) throws Exception {

        return smartParkDeviceService.getDevices(qo);
    }

    /**
     * 查询单个设备
     *
     * @param qo qo
     * @return
     */

    @RequestMapping("/getDeviceByMacAddr")
    public CommonResponseBody<SmartDeviceDTO> getDeviceByMacAddr(@RequestBody SmartDeviceNoAclRpcQO qo) throws Exception {

        return smartParkDeviceService.getDeviceNoAcl(qo);
    }

    /**
     * 保存设备
     *
     * @param smartDeviceDTO smartDeviceDTO
     * @return
     */
    @RequestMapping("/saveDevice")
    public CommonResponseBody<Boolean> saveDevice(@RequestBody SmartDeviceDTO smartDeviceDTO) {

        return smartParkDeviceService.saveDevice(smartDeviceDTO);
    }

    /**
     * 更新设备
     *
     * @param smartDeviceDTO smartDeviceDTO
     * @return
     */
    @RequestMapping("/updateDevice")
    public CommonResponseBody<Boolean> updateDevice(@RequestBody SmartDeviceDTO smartDeviceDTO) throws Exception {

        return smartParkDeviceService.updateDevice(smartDeviceDTO);
    }

    /**
     * 删除设备
     *
     * @param smartDeviceDTO smartDeviceDTO 参数只需要传id和租户id
     * @return
     */
    @RequestMapping("/delDevice")
    public CommonResponseBody<Boolean> delDevice(@RequestBody SmartDeviceDTO smartDeviceDTO) throws Exception {

        return smartParkDeviceService.deleteDevice(smartDeviceDTO);
    }


    /**
     * 重启设备
     *
     * @param smartDeviceRpcQO smartDeviceDTO
     * @return
     */
    @RequestMapping("/rebootDevice")
    public CommonResponseBody<Boolean> reboot(@RequestBody SmartDeviceRpcQO smartDeviceRpcQO) throws Exception {

        return smartParkDeviceService.rebootDevice(smartDeviceRpcQO);
    }


    /**
     * 查询设备设置信息
     *
     * @param qo qo
     * @return
     */
    @RequestMapping("/getDevicesSettings")
    public CommonResponseBody<SmartDeviceSettingsDTO> getDevicesSettings(@RequestBody SmartDeviceRpcQO qo) {

        return smartParkDeviceSettingsService.getDevicesSettings(qo);
    }

    /**
     * 保存设备设置信息
     *
     * @param smartDeviceDTO smartDeviceDTO
     * @return
     */
    @RequestMapping("/saveDeviceSettings")
    public CommonResponseBody<Boolean> saveDeviceSettings(@RequestBody SmartDeviceSettingsDTO smartDeviceDTO) throws Exception {

        return smartParkDeviceSettingsService.saveDeviceSettings(smartDeviceDTO);
    }

    /**
     * 更新设备设置信息
     *
     * @param smartDeviceDTO smartDeviceDTO
     * @return
     */
    @RequestMapping("/updateDeviceSettings")
    public CommonResponseBody<Boolean> updateDeviceSettings(@RequestBody SmartDeviceSettingsDTO smartDeviceDTO) throws Exception {

        return smartParkDeviceSettingsService.updateDeviceSettings(smartDeviceDTO);
    }


}
